import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useWritingStore = defineStore('writing', () => {
  const currentMode = ref('biography') // biography, diary, memoir
  const content = ref('')
  const bookmarks = ref([])
  const drafts = ref([])

  // 模拟AI建议问题
  const suggestedQuestions = ref({
    biography: [
      '您的童年是在哪里度过的？',
      '有什么重要的人生转折点？',
      '您最自豪的成就是什么？',
      '影响您最深的人是谁？'
    ],
    diary: [
      '今天发生了什么特别的事情？',
      '您现在的心情如何？',
      '有什么想要记录的感悟？',
      '今天学到了什么？'
    ],
    memoir: [
      '这段回忆发生在什么时候？',
      '当时的环境和背景是怎样的？',
      '您当时的感受是什么？',
      '这件事对您产生了什么影响？'
    ]
  })

  const setMode = (mode) => {
    currentMode.value = mode
  }

  const updateContent = (newContent) => {
    content.value = newContent
  }

  const addBookmark = (bookmark) => {
    bookmarks.value.push({
      id: Date.now(),
      title: bookmark.title,
      content: bookmark.content,
      mode: currentMode.value,
      createdAt: new Date().toISOString()
    })
  }

  const saveDraft = () => {
    if (content.value.trim()) {
      drafts.value.push({
        id: Date.now(),
        title: `${currentMode.value === 'biography' ? '传记' : currentMode.value === 'diary' ? '日记' : '回忆录'} - ${new Date().toLocaleDateString()}`,
        content: content.value,
        mode: currentMode.value,
        createdAt: new Date().toISOString()
      })
    }
  }

  const clearContent = () => {
    content.value = ''
  }

  return {
    currentMode,
    content,
    bookmarks,
    drafts,
    suggestedQuestions,
    setMode,
    updateContent,
    addBookmark,
    saveDraft,
    clearContent
  }
})
